<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<table>
	<thead>
		<tr>
			<th>Name</th>
			<th>Description</th>
			<th>Price</th>
			<th>Buy</th>
			<c:if test="${userLogged.logged}">
				<th>Edit</th>
				<th>Delete</th>
			</c:if>
		</tr>
	</thead>
	<tbody>
		<c:forEach items="${productList}" var="product">
			<tr>
				<td>${product.name}</td>
				<td>${product.description}</td>
				<td>R$ ${product.price}</td>
				<td>
					<!-- ADDING A ITEM TO BUY CART -->
					<form action="<c:url value="/cart" />" method="POST">
						<input type="hidden" name="item.product.id" value="${product.id}"/>
						<input class="qtty" name="item.quantity" value="1" />
						<button type="submit">BUY</button>
					</form>
				</td>
				<c:if test="${userLogged.logged}">
					<td>
						<a href="<c:url value="/products/${product.id}" />">Edit</a>
					</td>
					<td>
						<!-- WORKAROUND TO CALL HTTP DELETE METHOD -->
						<form action="<c:url value="/products/${product.id}" />" method="POST">
							<button class="link" name="_method" value="DELETE">Delete</button>
						</form>
					</td>
				</c:if>
			</tr>
		</c:forEach>
	</tbody>
</table>